package com.bdzl.flow.controller;

import com.bdzl.flow.service.ActNodeService;
import com.bdzl.flow.service.ActOdrStatusService;
import com.bdzl.pub.controller.BaseController;
import com.bdzl.pub.entity.flow.ActOdrStatusDO;
import com.bdzl.pub.entity.loan.OrderCallDO;
import com.bdzl.pub.entity.sys.UserDO;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 工作流订单状态表
 *
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-05-10 11:45:27
 */

@Controller
@RequestMapping("/bdzl/actOdrStatus")
public class ActOdrStatusController extends BaseController {
	@Autowired
	private ActOdrStatusService actOdrStatusService;
	@Autowired
	private ActNodeService actNodeService;


	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params) {
		//查询列表数据
		Query query = new Query(params);
		List<ActOdrStatusDO> actOdrStatusList = actOdrStatusService.list(params);
		int total = actOdrStatusService.count(query);
		PageUtils pageUtils = new PageUtils(actOdrStatusList, total);
		return pageUtils;
	}

	@ResponseBody
	@PostMapping("/query")
	public PageUtils query(@RequestBody Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<ActOdrStatusDO> actOdrStatusList = actOdrStatusService.list(params);
		int total = actOdrStatusService.count(query);
		PageUtils pageUtils = new PageUtils(actOdrStatusList, total);
		return pageUtils;
	}


	@GetMapping("/edit/{statId}")
	@ResponseBody
	public R edit(@PathVariable("statId") Integer statId){
		Map<String,Object> map = new HashMap<>();
		ActOdrStatusDO actOdrStatus = actOdrStatusService.get(statId);
		map.put("actOdrStatus", actOdrStatus);
	    return R.ok(actOdrStatus);
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save(@RequestBody ActOdrStatusDO actOdrStatus,HttpServletRequest request){
		//获取当前登录用户数据
		UserDO userInfo = actNodeService.getUserInfo(request);
		actOdrStatus.setStatCreuser(userInfo.getUserId());
		actOdrStatus.setStatCretime(new Date());
		if(actOdrStatusService.save(actOdrStatus)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update(@RequestBody ActOdrStatusDO actOdrStatus){
		actOdrStatusService.update(actOdrStatus);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove(@RequestBody Map<String, Object> params){
		Object statId = params.get("statId");
		if(actOdrStatusService.remove((Integer) statId)>0){
		return R.ok();
		}
		return R.error();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] statIds){
		actOdrStatusService.batchRemove(statIds);
		return R.ok();
	}

}
